home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / print / gs261sr1.zip / GDEVSUN.C < prev    next >
C/C++ Source or Header  |  1993-05-12  |  21KB  |  691 lines

  1. /* Copyright (C) 1989, 1992 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* gdevsun.c */
  20. /* SunView driver for Ghostscript */
  21. #include "gx.h"            /* for gx_bitmap; includes std.h */
  22.  
  23. #include <suntool/sunview.h>
  24. #include <suntool/canvas.h>
  25. #include <sunwindow/cms_mono.h>
  26. #include <stdio.h>
  27.  
  28. #include "gsmatrix.h"            /* needed for gxdevice.h */
  29. #include "gxdevice.h"
  30. #include "malloc_.h"
  31.  
  32. #ifndef DEFAULT_DPI
  33. #  define DEFAULT_DPI 75        /* Sun standard monitor */
  34. #endif
  35.  
  36. #ifdef A4
  37. #  define PAPER_X 8.27            /* A4 paper */
  38. #  define PAPER_Y 11.69
  39. #endif
  40.  
  41. #ifndef PAPER_X
  42. #  define PAPER_X 8.5            /* US letter paper */
  43. #  define PAPER_Y 11
  44. #endif
  45. /* Procedures */
  46. dev_proc_open_device(sun_open);
  47. dev_proc_sync_output(sun_sync);
  48. dev_proc_close_device(sun_close);
  49. dev_proc_map_rgb_color(sun_map_rgb_color);
  50. dev_proc_map_color_rgb(sun_map_color_rgb);
  51. dev_proc_fill_rectangle(sun_fill_rectangle);
  52. dev_proc_copy_mono(sun_copy_mono);
  53. dev_proc_copy_color(sun_copy_color);
  54. dev_proc_draw_line(sun_draw_line);
  55.  
  56. /* The device descriptor */
  57. private gx_device_procs sun_procs = {
  58.     sun_open,
  59.     gx_default_get_initial_matrix,
  60.     sun_sync,
  61.     gx_default_output_page,
  62.     sun_close,
  63.     sun_map_rgb_color,
  64.     sun_map_color_rgb,
  65.     sun_fill_rectangle,
  66.     gx_default_tile_rectangle,
  67.     sun_copy_mono,
  68.     sun_copy_color,
  69.     sun_draw_line,
  70.     gx_default_get_bits,
  71.     gx_default_get_props,
  72.     gx_default_put_props
  73. };
  74.  
  75. #define CMSNAME    "GHOSTVIEW"        /* SunView colormap name */
  76.  
  77. /* Define the SunView device */
  78. typedef struct gx_device_sun {
  79.     gx_device_common;
  80.     Frame frame;
  81.     Canvas canvas;
  82.     Pixwin *pw;
  83.     struct mpr_data mpr;
  84.     Pixrect    pr;
  85.     int truecolor;            /* use truecolor mapping */
  86.     int freecols;            /* unallocated colors */
  87.     byte *red, *green, *blue;    /* colormap */
  88.     char cmsname[sizeof(CMSNAME)+9];/* color map name */
  89. #if !arch_is_big_endian            /* need to swap bits & bytes */
  90. #  define BUF_WIDTH_BYTES (((int)(8.5*DEFAULT_DPI)+15)/16*2)
  91.     byte swap_buf[BUF_WIDTH_BYTES];
  92. #endif
  93. } gx_device_sun;
  94.  
  95. #if !arch_is_big_endian
  96. /* Define a table for reversing bit order. */
  97. static byte reverse_bits[256] = {
  98.   0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240,
  99.   8, 136, 72, 200, 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, 120, 248,
  100.   4, 132, 68, 196, 36, 164, 100, 228, 20, 148, 84, 212, 52, 180, 116, 244,
  101.   12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252,
  102.   2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242,
  103.   10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250,
  104.   6, 134, 70, 198, 38, 166, 102, 230, 22, 150, 86, 214, 54, 182, 118, 246,
  105.   14, 142, 78, 206, 46, 174, 110, 238, 30, 158, 94, 222, 62, 190, 126, 254,
  106.   1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81, 209, 49, 177, 113, 241,
  107.   9, 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, 57, 185, 121, 249,
  108.   5, 133, 69, 197, 37, 165, 101, 229, 21, 149, 85, 213, 53, 181, 117, 245,
  109.   13, 141, 77, 205, 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253,
  110.   3, 131, 67, 195, 35, 163, 99, 227, 19, 147, 83, 211, 51, 179, 115, 243,
  111.   11, 139, 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, 59, 187, 123, 251,
  112.   7, 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247,
  113.   15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255
  114. };
  115. #endif
  116.  
  117. /* The instance is public. */
  118. gx_device_sun gs_sunview_device = {
  119.     sizeof(gx_device_sun),
  120.     &sun_procs,
  121.     "sunview",
  122.      (int)(PAPER_X*DEFAULT_DPI), (int)(PAPER_Y*DEFAULT_DPI),    /* x and y extent */
  123.      DEFAULT_DPI, DEFAULT_DPI,    /* x and y density */
  124.     no_margins,
  125.     dci_color(0,0,0),    /* fill in later from display depth */
  126.      0,            /* connection not initialized */
  127. };
  128.  
  129. /* Macro for casting gx_device argument */
  130. #define xdev ((gx_device_sun *)dev)
  131.  
  132. /*
  133.  * The macros below define the colormap configuration used on 8-bit
  134.  * pseudo-color displays.
  135.  */
  136. /*
  137.  * The following macros define the number of bits used to represent rgb colors.
  138.  * The total must not exceed the display depth.
  139.  * Note that the RGB dimensions could have an uneven number of bits assigned
  140.  * to them, but that will cause dithering to not work very well, since
  141.  * gs assumes the dither ramp is the same for all 3 color dimensions.
  142.  *
  143.  * Setting RED_BITS to n will pre-allocate a color-cube of 2^(3n) entries.
  144.  * The remaining entries are allocated on demand for colors requested by
  145.  * sun_map_rgb_color(), until the color map is full. At that point gs will
  146.  * fall back onto dithering using the pre-allocated colors.
  147.  * As a special case, if RED_BITS = GREEN_BITS = BLUE_BITS = 0, only
  148.  * black and white are pre-allocated.
  149.  */
  150. #define RED_BITS    2        /* everything depends on this one */
  151. #define GREEN_BITS    RED_BITS
  152. #define BLUE_BITS    RED_BITS
  153. #define DEPTH        8        /* don't change this */
  154. #define RGB_BITS    (RED_BITS + GREEN_BITS + BLUE_BITS)
  155. /*
  156.  * Smallest # bits per dimension
  157.  */
  158. #define MAX_BITS    RED_BITS
  159. #if (GREEN_BITS > MAX_BITS)
  160. #undef MAX_BITS
  161. #define MAX_BITS    GREEN_BITS
  162. #endif
  163. #if (BLUE_BITS > MAX_BITS)
  164. #undef MAX_BITS
  165. #define MAX_BITS    BLUE_BITS
  166. #endif
  167. /*
  168.  * masks to pull out rgb components
  169.  */
  170. #define BLUE_MASK    ((1 << BLUE_BITS) - 1)
  171. #define GREEN_MASK    ((1 << (BLUE_BITS + GREEN_BITS)) - 1 - BLUE_MASK)
  172. #define RED_MASK    ((1 << (BLUE_BITS + GREEN_BITS + RED_BITS)) - 1 \
  173.              - BLUE_MASK - GREEN_MASK)
  174. /*
  175.  * number of colors on rgb dimensions
  176.  */
  177. #define RED_COLS    (1 << RED_BITS)
  178. #define GREEN_COLS    (1 << GREEN_BITS)
  179. #define BLUE_COLS    (1 << BLUE_BITS)
  180. #define RGB_COLS    (RED_COLS * GREEN_COLS * BLUE_COLS)
  181. #define MAX_COLS    (1 << MAX_BITS)
  182. /*
  183.  * maximum number of colors in map
  184.  */
  185. #define ALL_COLS    (1 << DEPTH)    /* 256 */
  186. #define CMS_SIZE    ALL_COLS    /* cut down to 64 or 128 for
  187.                        more cooperative behaviour */
  188.  
  189. #if (RGB_COLS > CMS_SIZE)        /* one is reserved for the scrollbar */
  190. CMS_SIZE_too_small_for_color_cube
  191. #endif
  192. #if (RGB_BITS < 0) || (RGB_BITS > DEPTH) 
  193. Display_does_not_support_this_many_colors
  194. #endif
  195.  
  196. /*
  197.  * The macros below define the color mapping used on 24-bit true-color
  198.  * displays.
  199.  * FAKE_TRUE_COLOR is used for debugging only.  It simulates a true-color
  200.  * type mapping on an 8-bit pseudo-color display.
  201. #define FAKE_TRUE_COLOR
  202.  */
  203. #ifdef FAKE_TRUE_COLOR
  204. # define TRUE_RED_BITS    3        /* everything depends on this one */
  205. # define TRUE_GREEN_BITS 2
  206. # define TRUE_BLUE_BITS    (DEPTH - TRUE_RED_BITS - TRUE_GREEN_BITS)
  207. #else
  208. # define TRUE_RED_BITS    8        /* everything depends on this one */
  209. # define TRUE_GREEN_BITS TRUE_RED_BITS
  210. # define TRUE_BLUE_BITS    TRUE_RED_BITS
  211. #endif ./* FAKE_TRUE_COLOR */
  212. #define TRUE_DEPTH    (TRUE_RED_BITS + TRUE_GREEN_BITS + TRUE_BLUE_BITS)
  213. /*
  214.  * Masks to pull out rgb components.  Note that the bit order is BGR from
  215.  * high to low order bits.
  216.  */
  217. #define TRUE_RED_MASK    ((1 << TRUE_RED_BITS) - 1)
  218. #define TRUE_GREEN_MASK    ((1 << (TRUE_RED_BITS + TRUE_GREEN_BITS)) - 1 \
  219.              - TRUE_RED_MASK)
  220. #define TRUE_BLUE_MASK    ((1 << (TRUE_RED_BITS + TRUE_GREEN_BITS \
  221.                     + TRUE_BLUE_BITS)) - 1 \
  222.              - TRUE_GREEN_MASK - TRUE_RED_MASK)
  223. /*
  224.  * number of colors on rgb dimensions
  225.  */
  226. #define TRUE_RED_COLS    (1 << TRUE_RED_BITS)
  227. #define TRUE_GREEN_COLS    (1 << TRUE_GREEN_BITS)
  228. #define TRUE_BLUE_COLS    (1 << TRUE_BLUE_BITS)
  229.  
  230. /* Initialize the device. */
  231. private Notify_value destroy_func();
  232. int
  233. sun_open(registe